package com.educate.serviceedu.controller;


import com.educate.commonutils.ResultOne;
import com.educate.serviceedu.entity.EduChapter;
import com.educate.serviceedu.entity.chapter.ChapterVo;
import com.educate.serviceedu.entity.vo.CourseInfoVo;
import com.educate.serviceedu.service.EduChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author educate.wht
 * @since 2022-08-16
 */
@RestController
@RequestMapping("/eduservice/chapter")
@CrossOrigin
public class EduChapterController {
    @Autowired
    private EduChapterService eduChapterService;
    //课程大纲列表
    @GetMapping("getChapterVideo/{courseId}")
    public ResultOne getChapterVideo(@PathVariable String courseId){
        List<ChapterVo> list=eduChapterService.getChapterVideoById(courseId);
        return ResultOne.ok().data("allChapterVideo",list);
    }
    //添加章节
    @PostMapping("addChapter")
    public ResultOne addChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.save(eduChapter);
        return ResultOne.ok();
    }
    //根据id查询
    @GetMapping("getChapterInfo/{chapterId}")
    public ResultOne getChapterInfo(@PathVariable String chapterId){
         EduChapter eduChapter= eduChapterService.getById(chapterId);
         return ResultOne.ok().data("chapter",eduChapter);
    }
    //修改章节
    @PostMapping("updateChapter")
    public ResultOne updateChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.updateById(eduChapter);
        return ResultOne.ok();
    }
    //删除章节
    @DeleteMapping("deleteChapter/{chapterId}")
    public ResultOne deleteChapter(@PathVariable String chapterId){
        boolean flag=eduChapterService.deleteChapter(chapterId);
        if(flag){
            return ResultOne.ok();
        }else{
            return ResultOne.error();
        }

    }


}

